package com.yanqu.road.server.cmd.pageant;

import com.yanqu.road.entity.activity.game.result.RankingDetailsResult;
import com.yanqu.road.pb.pageant.PageantProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.game2048.PageantModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = GameProtocol.S_CROSS_PAGEAN_DETAIL,desc = "选美详情跨服返回")
public class PageantRankDetailFromCrossCmd extends AbstractCommand {
    private RankingDetailsResult result;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        PageantProto.CrossPageantDetailRespMsg msg = PageantProto.CrossPageantDetailRespMsg.parseFrom(packet.getBytes());
        int activityId = msg.getActivityId();
        result = player.getModule(PageantModule.class).getRankingDetails(activityId);
        result.setTotalRanking(msg.getTotalRank());
        result.setNextTotalRanking(msg.getNextTotalValue());
        result.setRecordRanking(msg.getSingleRank());
        result.setNextRecordRanking(msg.getNextSingleValue());
    }

    @Override
    public void sendData(GamePlayer player) {
        PageantProto.PageantRankingDetailsRespMsg.Builder respMsg = PageantProto.PageantRankingDetailsRespMsg.newBuilder();
        if(0==ret&&0 == result.getRet()) {
            respMsg.setBeautyId(result.getBeautyId());
            respMsg.setTotalScore(result.getTotalScore());
            respMsg.setTotalRanking(result.getTotalRanking());
            respMsg.setNextTotalRanking(result.getNextTotalRanking());
            respMsg.setRecordScore(result.getRecordScore());
            respMsg.setRecordRanking(result.getRecordRanking());
            respMsg.setNextRecordRanking(result.getNextRecordRanking());
        } else {
            respMsg.setBeautyId(0);
            respMsg.setTotalScore(0);
            respMsg.setTotalRanking(0);
            respMsg.setNextTotalRanking(0);
            respMsg.setRecordScore(0);
            respMsg.setRecordRanking(0);
            respMsg.setNextRecordRanking(0);
        }
        player.sendPacket(Protocol.U_PAGEANT_RANKING_DETAIL, respMsg);
    }
}
